package com.edu.spring.ioc.config;

import com.edu.spring.ioc.datasource.MyDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 1.定义环境标识
 * 2.激活环境标识，明确告诉Spring当前处于什么环境，默认环境是什么
 */
@Configuration
public class DataSourceConfig {
    @Profile({"dev","default"}) // @Profile("环境标识")
    @Bean
    public MyDataSource dev() {
        MyDataSource myDataSource = new MyDataSource();
        myDataSource.setUrl("jdbc:mysql://localhost:3306/dev");
        myDataSource.setUsername("dev_user");
        myDataSource.setPassword("dev_pwd");
        return myDataSource;
    }

    @Profile("test")
    @Bean
    public MyDataSource test() {
        MyDataSource myDataSource = new MyDataSource();
        myDataSource.setUrl("jdbc:mysql://localhost:3306/test");
        myDataSource.setUsername("test_user");
        myDataSource.setPassword("test_pwd");
        return myDataSource;
    }

    @Profile("provided")
    @Bean
    public MyDataSource provided() {
        MyDataSource myDataSource = new MyDataSource();
        myDataSource.setUrl("jdbc:mysql://localhost:3306/provided");
        myDataSource.setUsername("provided_user");
        myDataSource.setPassword("provided_pwd");
        return myDataSource;
    }

}
